<?php

/**
  * Klasse Model
  * @param   :
  *
  * @info    : Klasse für den Datenzugriff
  *
  * @e.datum : 30.11.2010
  * @l.datum : 09.01.2010
  * @version : beta
 **/
class Model{

  /**
   *
  **/
  private static $forms = array(
                          array("id"=>0, "title"=>"Online Anmeldung am", "name"=>"bild", "active"=>true),
                          array("id"=>1, "title"=>"Eingabe Persönlichedaten", "name"=>"stu", "active"=>true),
                          array("id"=>2, "title"=>"Eingabe Erziehunsberechtiger", "name"=>"erz", "active"=>true),
                          array("id"=>3, "title"=>"Zuletzt besuchte Schule", "name"=>"schu", "active"=>true),
                          array("id"=>4, "title"=>"Ausbildung / Betrieb", "name"=>"ausb", "active"=>true)
  );


  /**
    * array("id"=>, "title"=>"", "name"=>"", "type"=>"", "validate"=>"", "pos"=>, "width"=>, "value"=>"", "active"=>true)
   **/
  private static $colForm = array(
      array( //Formular ID - 0 (Bildungsgang)
            array("id"=>0, "title"=>"Bildungsgang", "name"=>"kurswahl", "type"=>"select", "validate"=>"", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>1, "title"=>"Fachrichtung 1", "name"=>"fachr", "type"=>"radio", "validate"=>"", "pos"=>1, "width"=>100, "value"=>"richtung1", "active"=>false, "err"=>""),
            array("id"=>2, "title"=>"Fachrichtung 2", "name"=>"fachr", "type"=>"radio", "validate"=>"", "pos"=>2, "width"=>100, "value"=>"richtung2", "active"=>false, "err"=>"")
           ),

      array( //Formular ID - 1 (Persönlichedaten)
            array("id"=>0, "title"=>"Geschlecht", "name"=>"Geschlecht", "type"=>"select", "validate"=>"", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>1, "title"=>"Name", "name"=>"name", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>2, "title"=>"Vorname", "name"=>"vorname", "type"=>"input", "validate"=>"string", "pos"=>1, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>3, "title"=>"Straße", "name"=>"strasse", "type"=>"input", "validate"=>"string", "pos"=>2, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>4, "title"=>"Hausnr.", "name"=>"hausnr", "type"=>"input", "validate"=>"string", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>5, "title"=>"PLZ", "name"=>"plz", "type"=>"input", "validate"=>"string", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>6, "title"=>"Ort", "name"=>"ort", "type"=>"input", "validate"=>"string", "pos"=>4, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>7, "title"=>"Geburtsdatum", "name"=>"gebu", "type"=>"input", "validate"=>"date", "pos"=>4, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            //array("id"=>7, "title"=>"Geburtsdatum", "name"=>"gebu", "type"=>"date", "validate"=>"date", "pos"=>4, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>8, "title"=>"Geburtsort", "name"=>"gebuort", "type"=>"input", "validate"=>"string", "pos"=>5, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>9, "title"=>"Geburtsland", "name"=>"gebuland", "type"=>"select", "validate"=>"", "pos"=>6, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>10, "title"=>"Staatsangehörigkeit", "name"=>"staat", "type"=>"select", "validate"=>"", "pos"=>7, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>11, "title"=>"Religion", "name"=>"reli", "type"=>"select", "validate"=>"", "pos"=>8, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            //Spätaussiedler
            array("id"=>12, "title"=>"Spätaussiedler", "name"=>"", "type"=>"", "validate"=>"", "pos"=>9, "width"=>100, "value"=>"", "active"=>false, "err"=>""),
            //array("id"=>9, "title"=>"", "content"=>"Ja<input type='radio' name='spaus' value='ja'/> Nein<input type='radio' name='spaus' value='nein'/>", "type"=>"radio", "validate"=>""),
            array("id"=>13, "title"=>"Telefon", "name"=>"tele", "type"=>"input", "validate"=>"numeric", "pos"=>10, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>14, "title"=>"Handy", "name"=>"handy", "type"=>"input", "validate"=>"numeric", "pos"=>11, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>15, "title"=>"eMail", "name"=>"email", "type"=>"input", "validate"=>"email", "pos"=>12, "width"=>100, "value"=>"", "active"=>true, "err"=>"")
           ),
      array( //Formular ID - 2 (Erziehungsberechtiger)
            //Herr Frau
            array("id"=>0, "title"=>"Geschlecht", "name"=>"ergeschlecht", "type"=>"select", "validate"=>"", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>1, "title"=>"Name", "name"=>"ername", "type"=>"input", "validate"=>"", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>2, "title"=>"Vorname", "name"=>"ervorname", "type"=>"input", "validate"=>"", "pos"=>1, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>3, "title"=>"Straße", "name"=>"erstrasse", "type"=>"input", "validate"=>"", "pos"=>2, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>4, "title"=>"Hausnr.", "name"=>"erhausnr", "type"=>"input", "validate"=>"", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>5, "title"=>"PLZ", "name"=>"erplz", "type"=>"input", "validate"=>"", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>6, "title"=>"Ort", "name"=>"erort", "type"=>"input", "validate"=>"", "pos"=>5, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>7, "title"=>"Telefon", "name"=>"ertele", "type"=>"input", "validate"=>"", "pos"=>4, "width"=>100, "value"=>"", "active"=>true, "err"=>"")
           ),
      array( // Formular ID - 3 (LetzteSchule)
            array("id"=>0, "title"=>"Schulform", "name"=>"schform", "type"=>"select", "validate"=>"", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>1, "title"=>"Name der Schule", "name"=>"schname", "type"=>"input", "validate"=>"", "pos"=>1, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>2, "title"=>"Straße", "name"=>"schstrasse", "type"=>"input", "validate"=>"string", "pos"=>2, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>3, "title"=>"Hausnr.", "name"=>"schhausnr", "type"=>"input", "validate"=>"string", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>4, "title"=>"PLZ", "name"=>"schplz", "type"=>"input", "validate"=>"numeric", "pos"=>2, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>5, "title"=>"Ort", "name"=>"schort", "type"=>"input", "validate"=>"string", "pos"=>3, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>6, "title"=>"Jahr der Entlassung", "name"=>"schjahr", "type"=>"select", "validate"=>"", "pos"=>4, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>7, "title"=>"Art des Abschlusses", "name"=>"schabsch", "type"=>"input", "validate"=>"string", "pos"=>5, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
           ),
      array( //Formular ID - 4 (Ausbildung)
            array("id"=>0, "title"=>"Beruf inkl Fachrichtung", "name"=>"berfach", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>1, "title"=>"Ausbildungszeit von", "name"=>"bervon", "type"=>"input", "validate"=>"date", "pos"=>1, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>2, "title"=>"bis", "name"=>"berbis", "type"=>"input", "validate"=>"", "pos"=>2, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>3, "title"=>"Ausbildungsbetrieb", "name"=>"berbetrieb", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>4, "title"=>"Straße", "name"=>"berstrasse", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>5, "title"=>"Hausnr.", "name"=>"berhausnr", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>6, "title"=>"PLZ", "name"=>"berplz", "type"=>"input", "validate"=>"numeric", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>7, "title"=>"Ort", "name"=>"berort", "type"=>"input", "validate"=>"string", "pos"=>0,"width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>8, "title"=>"Telefon", "name"=>"bertele", "type"=>"input", "validate"=>"numeric", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>9, "title"=>"Telefax", "name"=>"bertelef", "type"=>"input", "validate"=>"numeric", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>10, "title"=>"eMail", "name"=>"bermail", "type"=>"input", "validate"=>"email", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>""),
            array("id"=>11, "title"=>"Ausbilder", "name"=>"berausb", "type"=>"input", "validate"=>"string", "pos"=>0, "width"=>100, "value"=>"", "active"=>true, "err"=>"")
           )
  );


  /**
   *
  **/
  private static $colData = array(
                            array( // Formular 0
                                  array( //col 0
                                        array("id"=>0, "contend"=>""),
                                        array("id"=>1, "contend"=>"Berufsschule (Duale Fachklassen)")
                                 )),

                            array( // Formular 1
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"Herr"),
                                      array("id"=>2, "contend"=>"Frau"),
                                  ), //col 0
                                  array(), //col 1
                                  array(), //col 2
                                  array(), //col 3
                                  array(), //col 4
                                  array(), //col 5
                                  array(), //col 6
                                  array(), //col 7
                                  array(), //col 8
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"Deutschland"),
                                      array("id"=>2, "contend"=>"England"),
                                      array("id"=>3, "contend"=>"anderes"),
                                  ), //col 9
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"deutsch"),
                                      array("id"=>2, "contend"=>"englisch"),
                                      array("id"=>3, "contend"=>"andere"),
                                  ), //col 10
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"RK"),
                                  ), //col 11

                                 ),
                            array( // Formular 2
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"Herr"),
                                      array("id"=>2, "contend"=>"Frau"),
                                  ), //col 0
                                 ),
                            array( // Formular 3
                                  array( // col 0
                                                  array("id"=>0, "contend"=>""),
                                                  array("id"=>1, "contend"=>"Sonderschule"),
                                                  array("id"=>2, "contend"=>"Hauptschule"),
                                                  array("id"=>3, "contend"=>"Realschule"),
                                                  array("id"=>4, "contend"=>"Gesamtschule"),
                                                  array("id"=>5, "contend"=>"Gymnasium"),
                                                  array("id"=>6, "contend"=>"Berufskolleg")),
                                  array(), //col 1
                                  array(), //col 2
                                  array(), //col 3
                                  array(), //col 4
                                  array(), //col 5
                                  array(
                                      array("id"=>0, "contend"=>""),
                                      array("id"=>1, "contend"=>"2000"),
                                      array("id"=>2, "contend"=>"2001"),
                                      array("id"=>3, "contend"=>"2002"),
                                      array("id"=>4, "contend"=>"2003"),
                                      array("id"=>5, "contend"=>"2004"),
                                      array("id"=>6, "contend"=>"2005"),
                                      array("id"=>7, "contend"=>"2006"),
                                      array("id"=>8, "contend"=>"2007"),
                                      array("id"=>9, "contend"=>"2008"),
                                      array("id"=>10, "contend"=>"2009"),
                                      array("id"=>11, "contend"=>"2010"),
                                  ), //col 6
                                ),
                            array( // Formular 4

                            )

  );


  /**
   *
  **/
  private static $formRistrict = array(

  );
  /**
   *
   * @return
  **/
  public static function getColForms (){
      require_once 'MySQL.php';
      $db = new MySQL();
      return $db->getArray("SELECT idfields AS id, title, name, type, pos, width, value, validate, active, error AS err, info, required, readonly, overview FROM formfields NATURAL JOIN fields WHERE active=1");
    return self::$colForm;
  }

  /**
   *
   * @param int $id Id des gesuchten Eintrags
   * @return
   *
  **/
  public static function getColForm($id){
      require_once 'MySQL.php';
      $db = new MySQL();
      return $db->getArray("SELECT idfields AS id, title, name, type, pos, width, value, validate, active, error AS err, info, required, readonly, overview FROM formfields NATURAL JOIN fields WHERE idforms='".$db->escapeParameter($id)."' AND active=1 ORDER BY pos");
    if(array_key_exists($id, self::$colForm)){
      return self::$colForm[$id];
    }else{
      return null;
    }
  }

  /**
   *
   * @return
  **/
  public static function getForms(){
      require_once 'MySQL.php';
      $db = new MySQL();
      return $db->getArray("SELECT idforms AS id, name, title, subtitle, precondition FROM forms");
    return self::$forms;
  }

  /**
   * Gibt einen bestimmten Eintrag zurück.
   * @param int $id Id des gesuchten Eintrags
   * @return
   *
  **/
  public static function getForm($id){
      require_once 'MySQL.php';
      $db = new MySQL();
      return $db->getArray("SELECT idforms AS id, name, title, subtitle, precondition FROM forms WHERE idforms='".$db->escapeParameter($id)."'");
    if(array_key_exists($id, self::$forms)){
      return self::$forms[$id];
    }else{
      return null;
    }
  }

  /**
   * Gibt einen bestimmten Eintrag zurück.
   * @param int $id Id des gesuchten Eintrags
   * @return Array Array, dass einen Eintrag repräsentiert, bzw.
   *                  wenn dieser nicht vorhanden ist, null.
 **/
  public static function getColData($id){
      require_once 'MySQL.php';
      $db = new MySQL();
      $result = $db->getArray("SELECT data.iddata AS id, content AS contend FROM data NATURAL JOIN fielddata WHERE idfields =$id ORDER BY content");
      return $result;
      return $db->getArray("SELECT data.iddata, content AS contend FROM formfields
              JOIN fields ON formfields.idfields= fields.idfields
              JOIN fielddata ON fields.idfields = fielddata.idfields
              JOIN data ON fielddata.iddata = data.iddata
              WHERE idforms='".$db->escapeParameter($id)."'");
    //return self::$colData;
    if(array_key_exists($id, self::$colData)){
      return self::$colData[$id];
    }else{
      return null;
    }
  }
}


/*
 private static $colForm = array(
      array( //Formular ID - 0 (Bildungsgang)
            array("id"=>0, "title"=>"Bildungsgang", "content"=>"<SELECT name='kurswahl'>
                                                                      <option>Berufsschule (Duale Fachklassen)</option>
                                                                      <option>Techniker Informatik</option>
                                                                </SELECT>", "type"=>"select", "validate"=>""),
            array("id"=>1, "title"=>"Fachrichtung 1", "content"=>"<input type='radio' name='fach' value='richtung1' />", "type"=>"radio", "validate"=>""),
            array("id"=>2, "title"=>"Fachrichtung 2", "content"=>"<input type='radio' name='fach' value='richtung2' />", "type"=>"radio", "validate"=>"")
           ),

      array( //Formular ID - 1 (Persönlichedaten)
            array("id"=>0, "title"=>"Name", "content"=>"<input name='name' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>1, "title"=>"Vorname", "content"=>"<input name='vorname' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>2, "title"=>"Straße / Nr", "content"=>"<input name='strasse' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>3, "title"=>"PLZ / Ort", "content"=>"<input name='plz' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>4, "title"=>"Geburtsdatum", "content"=>"<input name='gebu' value=''></input>", "type"=>"input", "validate"=>"date"),
            array("id"=>5, "title"=>"Geburtsort", "content"=>"<input name='gebuort' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>6, "title"=>"Geburtsland", "content"=>"<input name='gebuland' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>7, "title"=>"Staatsangehörigkeit", "content"=>"<input name='staat' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>8, "title"=>"Religion", "content"=>"<input name='reli' value=''></input>", "type"=>"input", "validate"=>"string"),
            array("id"=>9, "title"=>"Spätaussiedler", "content"=>"Ja<input type='radio' name='spaus' value='ja'/> Nein<input type='radio' name='spaus' value='nein'/>", "type"=>"radio", "validate"=>""),
            array("id"=>10, "title"=>"Telefon", "content"=>"<input name='tele' value=''></input>", "type"=>"input", "validate"=>"numeric"),
            array("id"=>11, "title"=>"Handy", "content"=>"<input name='handy' value=''></input>", "type"=>"input", "validate"=>"numeric"),
            array("id"=>12, "title"=>"eMail", "content"=>"<input name='email' value=''></input>", "type"=>"input", "validate"=>"email")
           ),
      array( //Formular ID - 2 (Erziehungsberechtiger)
            array("id"=>0, "title"=>"Name", "content"=>"<input name='ername'></input>", "type"=>"input", "validate"=>""),
            array("id"=>1, "title"=>"Vorname", "content"=>"<input name='ervorname'></input>", "type"=>"input", "validate"=>""),
            array("id"=>2, "title"=>"Straße", "content"=>"<input name='erstrasse'></input>", "type"=>"input", "validate"=>""),
            array("id"=>3, "title"=>"PLZ / Ort", "content"=>"<input name='erort'></input>", "type"=>"input", "validate"=>""),
            array("id"=>4, "title"=>"Telefon", "content"=>"<input name='ertele'></input>", "type"=>"input", "validate"=>"")
           ),
      array( // Formular ID - 3 (LetzteSchule)
            array("id"=>0, "title"=>"Schulform", "content"=>"<select name='schform'>
                                                                 <option>Sonderschule</option>
                                                                 <option>Hauptschule</option>
                                                                 <option>Realschule</option>
                                                                 <option>Gesamtschule</option>
                                                                 <option>Gymnasium</option>
                                                                 <option>Berufskolleg</option>
                                                              </select>", "type"=>"select", "validate"=>""),
            array("id"=>1, "title"=>"Name der Schule", "content"=>"<input name='schname'></input>", "type"=>"input", "validate"=>""),
            array("id"=>2, "title"=>"Straße", "content"=>"<input name='schstrasse'></input>", "type"=>"input", "validate"=>""),
            array("id"=>3, "title"=>"PLZ / Ort", "content"=>"<input name='schort'></input>", "type"=>"input", "validate"=>""),
            array("id"=>4, "title"=>"Jahr der Entlassung", "content"=>"<input name='schjahr'></input>", "type"=>"input", "validate"=>"numeric"),
            array("id"=>5, "title"=>"Art des Abschlusses", "content"=>"<input name='schabsch'></input>", "type"=>"input", "validate"=>"string")
           ),
      array( //Formular ID - 4 (LetzteSchule)
            array("id"=>0, "title"=>"Beruf inkl Fachrichtung", "content"=>"<input name='berfach'></input>", "validate"=>""),
            array("id"=>1, "title"=>"Vertragliche Ausbildungszeit", "content"=>"<input name='bervon'></input> bis
                                                                                <input name='berbis'></input>", "type"=>"select", "validate"=>""),
            array("id"=>2, "title"=>"Ausbildungsbetrieb", "content"=>"<input name='berbetrieb'></input>", "type"=>"input", "validate"=>""),
            array("id"=>3, "title"=>"Straße", "content"=>"<input name='berstrasse'></input>", "type"=>"input", "validate"=>""),
            array("id"=>4, "title"=>"PLZ / Ort", "content"=>"<input name='berort'></input>", "type"=>"input", "validate"=>""),
            array("id"=>5, "title"=>"Telefon", "content"=>"<input name='bertele'></input>", "type"=>"input", "validate"=>""),
            array("id"=>6, "title"=>"Telefax", "content"=>"<input name='bertelef'></input>", "type"=>"input", "validate"=>""),
            array("id"=>7, "title"=>"eMail", "content"=>"<input name='bermail'></input>", "type"=>"input", "validate"=>""),
            array("id"=>8, "title"=>"Ausbilder", "content"=>"<input name='berausb'></input>", "type"=>"input", "validate"=>"")
           )
  );*/
?>